/**     
 * @Title: NettyRequestDispatcher.java   
 * @Package me.springboot.netty.dispatcher   
 * @Description: TODO
 * @author weiwei 
 * @date 2017年8月25日 下午2:31:40   
 * @version V1.0     
 */
package me.springboot.netty.dispatcher;

import java.io.IOException;

import javax.servlet.DispatcherType;
import javax.servlet.FilterChain;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import me.springboot.netty.servlet.NettyHttpServletRequest;

/**
 * @ClassName: NettyRequestDispatcher
 * @Description: TODO
 * @author weiwei
 * @date 2017年8月25日 下午2:31:40
 * 
 */
public class NettyRequestDispatcher implements RequestDispatcher {

	@SuppressWarnings("unused")
	private final ServletContext context;

	private final FilterChain filterChain;

	public NettyRequestDispatcher(ServletContext context, FilterChain filterChain) {
		this.context = context;
		this.filterChain = filterChain;
	}

	@Override
	public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException {
		request.setAttribute(NettyHttpServletRequest.DISPATCHER_TYPE, DispatcherType.FORWARD);
		// TODO implement
	}

	@Override
	public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
		request.setAttribute(NettyHttpServletRequest.DISPATCHER_TYPE, DispatcherType.INCLUDE);
		// TODO implement
	}

	public void dispatch(ServletRequest request, ServletResponse response) throws ServletException, IOException {
		request.setAttribute(NettyHttpServletRequest.DISPATCHER_TYPE, DispatcherType.ASYNC);
		filterChain.doFilter(request, response);
	}
}
